package com.spic.business.train.files.controller;

import com.spic.business.common.core.utils.poi.BusinessExcelUtil;
import com.spic.business.train.files.domain.TrainInfoFiles;
import com.spic.business.train.files.service.ITrainInfoFilesService;
import com.spic.common.core.utils.SecurityUtils;
import com.spic.common.core.utils.UUIDUtil;
import com.spic.common.core.utils.poi.ExcelUtil;
import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.web.page.TableDataInfo;
import com.spic.common.log.annotation.Log;
import com.spic.common.log.enums.BusinessType;
import com.spic.common.security.annotation.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 培训附件(除证书、心得体会以外的附件)Controller
 *
 * @author spic
 * @date 2021-10-15
 */
@RestController
@RequestMapping("/train/files")
public class TrainInfoFilesController extends BaseController
{
    @Autowired
    private ITrainInfoFilesService trainInfoFilesService;

    /**
     * 查询培训附件(除证书、心得体会以外的附件)列表
     */
    @PreAuthorize(hasPermi = "business/train:files:list")
    @GetMapping("/list")
    public TableDataInfo list(TrainInfoFiles trainInfoFiles)
    {
        startPage();
        List<TrainInfoFiles> list = trainInfoFilesService.selectTrainInfoFilesList(trainInfoFiles);
        return getDataTable(list);
    }

    /**
     * 导出培训附件(除证书、心得体会以外的附件)列表
     */
    @PreAuthorize(hasPermi = "business/train:files:export")
    @Log(title = "培训附件(除证书、心得体会以外的附件)", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrainInfoFiles trainInfoFiles) throws IOException
    {
        List<TrainInfoFiles> list = trainInfoFilesService.selectTrainInfoFilesList(trainInfoFiles);
        ExcelUtil<TrainInfoFiles> util = new BusinessExcelUtil<TrainInfoFiles>(TrainInfoFiles.class);
        util.exportExcel(response, list, "培训附件(除证书、心得体会以外的附件)数据");
    }

    /**
     * 获取培训附件(除证书、心得体会以外的附件)详细信息
     */
    @PreAuthorize(hasPermi = "business/train:files:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(trainInfoFilesService.selectTrainInfoFilesById(id));
    }

    /**
     * 新增培训附件(除证书、心得体会以外的附件)
     */
    @PreAuthorize(hasPermi = "business/train:files:add")
    @Log(title = "培训附件(除证书、心得体会以外的附件)", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TrainInfoFiles trainInfoFiles)
    {
        trainInfoFiles.setId(UUIDUtil.createUUID());
        trainInfoFiles.setCreateBy(String.valueOf(SecurityUtils.getUserId()));
        return toAjax(trainInfoFilesService.insertTrainInfoFiles(trainInfoFiles));
    }

    /**
     * 修改培训附件(除证书、心得体会以外的附件)
     */
    @PreAuthorize(hasPermi = "business/train:files:edit")
    @Log(title = "培训附件(除证书、心得体会以外的附件)", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TrainInfoFiles trainInfoFiles)
    {
        return toAjax(trainInfoFilesService.updateTrainInfoFiles(trainInfoFiles));
    }

    /**
     * 删除培训附件(除证书、心得体会以外的附件)
     */
    @PreAuthorize(hasPermi = "business/train:files:remove")
    @Log(title = "培训附件(除证书、心得体会以外的附件)", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable String id)
    {
        return toAjax(trainInfoFilesService.deleteTrainInfoFilesById(id));
    }
}
